package ServiceLayer;

import java.util.Collection;

import DAL.Pipeline;
import DALFacades.IFacade;
import DomainLayer.*;
import Helpers.ApplicationLogger;

public class ServiceFacade {

	private IFacade currentFacade;

    public boolean AddMessage(String message, String userIdFrom, String userIdTo, boolean aPrivate) {
        return false;  //To change body of created methods use File | Settings | File Templates.
    }

    private static final class Nested {

        static final ServiceFacade _instance = new ServiceFacade();
    }
	public static ServiceFacade getInstance() {
		return Nested._instance;
	}

	public ServiceFacade() {
		currentFacade = Pipeline.getInstance().getFacade();
	}

	public void AddNotification(String contentString) throws Throwable {
		ApplicationLogger.getInstance().LOG.info("call method AddNotification");

		// currentFacade.AddNotification(contentString);
	}

	public Collection<MessageEntity> GetMessagesByUserId(String userIdString)
			throws Throwable {
		ApplicationLogger.getInstance().LOG
				.info("Call method GetMessagesByUserId");

		Collection<MessageEntity> messageList = null;

		// messageList = currentFacade.GetMessagesByUserId(userIdString);
		ApplicationLogger.getInstance().LOG.info("Result is " + messageList);
		return messageList;
	}

	public Object LoadImage(Object imageNameString, Object imageByteArray)
			throws Throwable {
		// TODO Auto-generated method stub
		return null;
	}

	public Object GetImageById(String keyString) throws Throwable {
		// TODO Auto-generated method stub
		return null;
	}

	public Object LoadImage(String imageNameString, Object imageByteArray)
			throws Throwable {
		// TODO Auto-generated method stub
		return null;
	}

	public void DeleteImage(String imageNameString) throws Throwable {
		// TODO Auto-generated method stub

	}

	public Object GetLastNView() throws Throwable {
		// TODO Auto-generated method stub
		return null;
	}

	public UserEntity AuthentificationByLoginAndPassword(String login,
			String password) throws Throwable {
		ApplicationLogger.getInstance().LOG
				.info("Call method AuthentificationByLoginAndPassword");

		UserEntity user = null;

		user = currentFacade
				.AuthentificationByLoginAndPassword(login, password);
		ApplicationLogger.getInstance().LOG.info("Result is " + user);
		return user;
	}

	public Boolean UpdateUser(UserEntity user) throws Throwable {
		Boolean result = false;
		result = currentFacade.UpdateUser(user);
		return result;
	}

	public ICommentable GetICommentableObjectByIdAndType(int id,
			String objectType) {
		ApplicationLogger.getInstance().LOG
				.info("Call method GetICommentableObjectByIdAndType");

		ICommentable object = null;
		object = currentFacade.GetICommentableObjectByIdAndType(id, objectType);
		ApplicationLogger.getInstance().LOG.info("Result is " + object);
		return object;
	}

	public Boolean AddCommentary(ICommentable entity) throws Throwable {
		ApplicationLogger.getInstance().LOG.info("Call method AddCommentary");
		Boolean result = currentFacade.AddCommentary(entity);
		ApplicationLogger.getInstance().LOG.info("Result is " + result);
		return result;
	}

    public Boolean RemoveCommentary(int commentaryId) throws Throwable {
        ApplicationLogger.getInstance().LOG.info("Call method RemoveCommentary");
        Boolean result = currentFacade.RemoveCommentary(commentaryId);
        ApplicationLogger.getInstance().LOG.info("Result is " + result);
        return result;
    }
    
    public Boolean UpdateCommentary(CommentaryEntity commentary) {
        ApplicationLogger.getInstance().LOG.info("Call method UpdateCommentary");
        Boolean result = currentFacade.UpdateCommentary(commentary);
        ApplicationLogger.getInstance().LOG.info("Result is " + result);
        return result;
    }

    public CommentaryEntity GetCommentaryById(int commentaryId) {
        ApplicationLogger.getInstance().LOG.info("Call method UpdateCommentary");
        CommentaryEntity result = currentFacade.GetCommentaryById(commentaryId);
        ApplicationLogger.getInstance().LOG.info("Result is " + result);
        return result;
    }

	public UserEntity GetUserById(int id) {
		ApplicationLogger.getInstance().LOG.info("Call method GetUserById");

		UserEntity user = null;
		user = currentFacade.GetUserById(id);
		ApplicationLogger.getInstance().LOG.info("Result is " + user);
		return user;
	}

	// public Boolean AddMessage(String message,
	// String userIdForm,
	// String userIdTo,
	// boolean isPrivate) throws Throwable {
	// ApplicationLogger.getInstance().LOG.info("Call method AddMessage");
	//
	// boolean result = false;
	//
	// //result = currentFacade.AddMessage(message, userIdForm, userIdTo,
	// isPrivate);
	// ApplicationLogger.getInstance().LOG.info("Result is " + result);
	// return result;
	// }

	public Boolean AddFeedBack(String page, String from, String message)
			throws Throwable {
		ApplicationLogger.getInstance().LOG.info("Call method AddFeedBack");
		Boolean result = false;
		result = currentFacade.SetFeedBackEntity(message, from, page);
		ApplicationLogger.getInstance().LOG.info("Status of AddFeedBack is "
				+ result);
		return result;
	}

	public Collection<AbstractEntity> GetFeedBack() throws Throwable {
		ApplicationLogger.getInstance().LOG.info("Call method GetFeedBack");
		Collection<AbstractEntity> feedbacklist = null;
		feedbacklist = currentFacade.GetFeedBackEntity();
		ApplicationLogger.getInstance().LOG.info("Result is" + feedbacklist);
		return feedbacklist;
	}

	public Boolean RegistrationUser(String firstName, String secondName,
			String middleName, String login, String password, String gender,
			Integer age, String sessionId, String lastIP) throws Throwable {
		ApplicationLogger.getInstance().LOG
				.info("Call method RegistrationUser");
		Boolean result = false;
		result = currentFacade.AddUser(firstName, secondName, middleName,
				login, password, gender, age, sessionId, lastIP);
		ApplicationLogger.getInstance().LOG.info("Registration is resolved: "
				+ result);
		return result;
	}

	public Boolean ChangeUser(String login, String password, String firstName,
			String secondName, String middleName, String gender, Integer age)
			throws Throwable {
		ApplicationLogger.getInstance().LOG.info("Call method ChangeUser");
		Boolean result = false;
		result = currentFacade.ChangeUser(login, password, firstName,
				secondName, middleName, gender, age);
		ApplicationLogger.getInstance().LOG.info("Change is resolved: "
				+ result);
		return result;
	}

	public Collection<AbstractEntity> GetMovies(String requiredName)
			throws Throwable {
		ApplicationLogger.getInstance().LOG.info("Call method GetMovies");

		Collection<AbstractEntity> movies = null;
		movies = currentFacade.GetMovies(requiredName);
		ApplicationLogger.getInstance().LOG.info("Result is " + movies);
		return movies;
	}

	public Collection<AbstractEntity> GetFirstTenMovies() throws Throwable {
		ApplicationLogger.getInstance().LOG
				.info("Call method GetFirstTenMovies");

		Collection<AbstractEntity> movies = null;
		movies = currentFacade.GetFirstTenMovies();
		ApplicationLogger.getInstance().LOG.info("Result is " + movies);
		return movies;
	}
	
	public Boolean AddMovie(MovieEntity movieEntity) throws Throwable {
		ApplicationLogger.getInstance().LOG.info("Call method AddMovie");
		Boolean result = false;
		result = currentFacade.AddMovie(movieEntity);
		ApplicationLogger.getInstance().LOG.info("Status of AddMovie is "
				+ result);
		return result;
	}
}
